import { Modal } from "antd";
import { useContext, createContext, type PropsWithChildren } from "react";
import type { HookAPI } from "antd/es/modal/useModal";

const ModalContext = createContext({} as HookAPI);

export function useModal() {
  return useContext(ModalContext);
}

export default function AntdModalProvider({ children }: PropsWithChildren) {
  const [api, context] = Modal.useModal();
  return (
    <>
      {context}
      <ModalContext.Provider value={api}>{children}</ModalContext.Provider>
    </>
  );
}
